package org.platform.core.filecommand;

import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.quartz.InterruptableJob;
import org.quartz.JobExecutionContext;

/**
 * @author
 */
@Slf4j
public class BaseFileCommandJob implements InterruptableJob {
    @Override
    public void interrupt() {

    }

    @Override
    public void execute(JobExecutionContext context) {
        String filePath = context.getJobDetail().getJobDataMap().getString("FilePath");
        //无后缀的文件名
        String fileName = context.getJobDetail().getJobDataMap().getString("FileName");
        String txtMsg = context.getJobDetail().getJobDataMap().getString("txtMsg");


        //找对应的实现类
        String[] fileTypes = fileName.split("_");
        if (fileTypes.length < 1) {
            return;
        }
        String fileType = fileTypes[0];
        String iFileCommandName = StringUtils.join("org.platform.core.filecommand.impl.", fileType, "FileCommand");
        try {
            Class<?> commandClassName = Class.forName(iFileCommandName);
            IFileCommand iFileCommand = (IFileCommand) commandClassName.newInstance();
            iFileCommand.doCommandAck(filePath, fileName, txtMsg);
        } catch (ClassNotFoundException e) {
            log.error("未找到对应的实现类: {}", iFileCommandName);
        } catch (IllegalAccessException | InstantiationException e) {
            log.error("类: {} 实例化异常:  {}", iFileCommandName, e);
        }

    }
}

